package com.zzyl.controller;


import com.github.xiaoymin.knife4j.annotations.ApiOperationSupport;
import com.zzyl.base.ResponseResult;
import com.zzyl.dto.DeptDto;
import com.zzyl.dto.ResourceDto;
import com.zzyl.service.ResourceService;
import com.zzyl.service.RoleService;
import com.zzyl.vo.DeptVo;
import com.zzyl.vo.ResourceVo;
import com.zzyl.vo.TreeVo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/resource")
@Slf4j
@Api(tags = "资源管理")
public class ResourceController {

    @Autowired
    ResourceService resourceService;



    @PostMapping("/list")
    @ApiOperation(value = "资源列表", notes = "资源列表")
    @ApiImplicitParam(name = "ResourceDto", value = "资源DTO对象", required = true, dataType = "ResourceDto")
    @ApiOperationSupport(includeParameters = {"deptDto.dataState", "deptDto.deptName", "deptDto.parentDeptNo"})
    public ResponseResult<List<ResourceVo>> resourceList(@RequestBody ResourceDto resourceDto) {
        List<ResourceVo> resourceList = resourceService.findResourceList(resourceDto);
        return ResponseResult.success(resourceList);
    }

    @PostMapping("/tree")
    @ApiOperation(value = "资源树形", notes = "资源树形")
    public ResponseResult<TreeVo> ResourceTreeVo(@RequestBody ResourceDto resourceDto) {
        TreeVo treeVo = resourceService.ResourceTreeVo(resourceDto);
        return ResponseResult.success(treeVo);
    }

    //资源增加
    @PutMapping
    @ApiOperation(value = "资源增加", notes = "资源增加")
    public ResponseResult<ResourceVo> addResource(@RequestBody ResourceDto resourceDto) {

        return ResponseResult.success(resourceService.createResource(resourceDto));

    }
    //删除菜单
    @DeleteMapping("/{resourceNo}")
    @ApiOperation(value = "删除菜单")
    public ResponseResult deleteByresource(@PathVariable("resourceNo") List<String> resourceNo) {

        log.info("角色删除的数据：{}", resourceNo);

    resourceService.deleteByresourceNo(resourceNo);

        return ResponseResult.success();
    }
}
